//Sava user data
var savaData ={
	//Obtain form data
	"getFormData":function(data){
		var oldPassword = $("#oldPassword").val();
		var determinePassWord = $("#determinePassWord").val();
		var userId = $("#userId").val();
		var jsons = {
			 "userId":userId,
			 "pwd1":oldPassword,
			 "pwd2":determinePassWord,
		};
		return jsons;
	},
	//postAjax
	"postAjax":function(){
		$.ajax({
	        type: "POST",
	        url: basePath+"user/mpdifyPwd.do",
	        data: savaData.getFormData(),
	        success: function (data) {
	            if (data.returnCode==10000) {
	                //layer.msg(data.returnMessage+"请重新登录！，",2,10);
	            	$.ajax({
	                    type: "POST",
	                    url: basePath+"user/logout.do",
	                    success: function (data2) {
	                        if (data2.returnCode==10000){
	                        	var urls = basePath+"login/login.jsp";
	                            setTimeout("javascript:location.href='"+urls+"'", 3000);
	                        	setInterval("run()", 1000);
	                            layer.msg("密码修改成功！，<strong class='theCountdown'>"+s+"</strong> 秒后前往登录页",50,-1);
	                        }else{
	                        	layer.msg(data2.returnMessage,1,-1);
	                        }
	                    },
	                    error: function (message) {
	                      	 layer.msg("退出失败",2,-1);
	                    }
	                });			
	               // SignOut();
	            } else if(data.returnCode==999994){
                    setUserTimeout(data);
                }else{
	            	layer.msg(data.returnMessage,2,-1);
	            	$("#oldPassword").focus();
	            	$("#oldPasswordNotice").html("<span class='false'></span>");
	            }
	        },
	        error: function (message) {
	          	 layer.msg(message,2,-1);
	        }
	    });	
	}
};

//点击修改 
$("#editPasswordForm").validationEngine('attach',{
	showOneMessage: true,
	binded:true,
	scroll:false,
	"focusFirstField":true,
	"maxErrorsPerField":"1",
	validationEventTrigger:"blur",
	addSuccessCssClassToField:"trueFieldElement",//元素验证通过，添加class
	addFailureCssClassToField:"falseFieldElement",
	onFieldSuccess:onFieldSuccess, //验证通过后回调
	onFieldFailure:onFieldFailure //验证失败后回调
});
function setYanZheng(){
    var isSuccess = $('#editPasswordForm').validationEngine('validate');
    console.log(isSuccess);
    if(isSuccess==true){
    	savaData.postAjax();
    }
}
$("#editPasswordBtn").live("click",function(){
	setYanZheng();
});
$('.enterKeyDownElement').keydown(function(e){
	if(e.keyCode==13){
		setYanZheng();
	}
});	
function onFieldSuccess(){
	$(".trueFieldElement").parent(".f_ccc").siblings(".f_rrr").find(".tiShiText").html("<span class='true'></span>");
}
function onFieldFailure(){
	$(".falseFieldElement").parent(".f_ccc").siblings(".f_rrr").find(".tiShiText").html("<span class='false'></span>");
}





